<script setup>
  import {ref} from "vue";

  const a=ref({name:'',salary:'',job:''});
  const o=ref([]);

  const s=()=>{

    if (a.value.name.trim()=='' || a.value.job.trim()=='' || a.value.salary.trim()==''){
        alert('请输入数据');
        return;
    }
    o.value.push(a.value);
    a.value={name:'',salary:'',job:''};
    console.log(o.value,typeof o.value);

  };


</script>

<template>
  <h1>员工列表练习</h1>
  <input type="text" placeholder="请输入员工姓名" v-model="a.name">
  <input type="text" placeholder="请输入员工工资" v-model="a.salary">
  <input type="text" placeholder="请输入员工岗位" v-model="a.job">
  <button @click="s">添加员工</button>
  <hr>
  <table border="1px">
    <tr>
      <th>编号</th>
      <th>姓名</th>
      <th>工资</th>
      <th>岗位</th>
    </tr>
    <tr v-for="(item,index) in o">
      <td>{{index+1}}</td>
      <td>{{item.name}}</td>
      <td>{{item.salary}}</td>
      <td>{{item.job}}</td>
    </tr>
  </table>
</template>

<style scoped>

</style>